import 'package:get/get.dart';

import '../../../../common/api/x_ali_face_detection_assemble_control.dart';
import '../../../../common/services/shared_preference_service.dart';
import '../../../../common/utils/log_util.dart';
import '../../../common/face_check_page/face_registration/index.dart';
import 'index.dart';

class AttendanceSettingController extends GetxController {
  AttendanceSettingController();

  final state = AttendanceSettingState();

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    state.aliFaceRegistration =
        AppAliFaceDetectionAssembleControlService.to.isInstall();
    state.onDutyFastCheckInEnable = SharedPreferenceService.to
        .getBool(SharedPreferenceService.attendanceOnDutyFastCheckinKey);
    state.offDutyFastCheckInEnable = SharedPreferenceService.to
        .getBool(SharedPreferenceService.attendanceOffDutyFastCheckinKey);
    super.onReady();
  }

  void openFaceRegistration() {
    FaceRegistrationPage.open();
  }

  void switchOnDutyFastCheckin(bool value) {
    OLogger.d('onDuty $value');
    state.onDutyFastCheckInEnable = value;
    SharedPreferenceService.to
        .putBool(SharedPreferenceService.attendanceOnDutyFastCheckinKey, value);
  }

  void switchOffDutyFastCheckin(bool value) {
    OLogger.d('offDuty $value');
    state.offDutyFastCheckInEnable = value;
    SharedPreferenceService.to.putBool(
        SharedPreferenceService.attendanceOffDutyFastCheckinKey, value);
  }
}
